﻿using STHPMS1.Common.C_Entity;
using STHPMS1.Common.C_Entity.Stmpms1;
using STHPMS1.ICore;
using STHPMS1.ICore.I_Core;
using STHPMS1.ICore.I_UI;
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace STHPMS1.Web.W_Controller
{
    [RoutePrefix("api/rdpci")]
    public class T_RdpciPage1Controller : STHPMS1.Web.W_Core.MyController
    {
        [Route("")]
        [Route("page/{page?}", Name = "GetrdpciByPage")]
        [Route("rows/{rows?}")]
        [Route("page/{page?}/rows/{rows?}")]
        public IHttpActionResult Get(int? region = null, int? direction = null, DateTime? checkDate=null, int page = 1,  int rows = 10)
        {
            int p = page;
            int s = rows;

            PagingInfo info = new PagingInfo();
            info.PageIndex = p> 0 ? p - 1 : 0;
            info.PageSize = s;
            info.TotalRecords = 0;

            var data=this.Scene.Bll.T_Rdpci.Get<T_Rdpci>(null, info).ToArray();
            if(data==null) return NotFound();

            var result = new { rows = data, total = info.TotalRecords };

            return Ok(result);
        }

        [Route("")]
        public HttpResponseMessage Post(T_Rdpci entity)
        {
            this.Scene.Bll.T_Rdpci.Save(entity);

            var response = Request.CreateResponse(HttpStatusCode.Created);
            // Generate a link to the new book and set the Location header in the response.
            string uri = Url.Link("GetT_RdpciByPage", new { page = 1 });
            response.Headers.Location = new Uri(uri);

            return response;
        }

        [Route("")]
        public void Delete(T_Rdpci entity)
        {
            this.Scene.Bll.T_Rdpci.Remove(entity);
        }
    }
}